package com.eve.eplus.common.adapter;

import java.util.ArrayList;
import java.util.HashMap;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.eve.eplus.R;
import com.eve.eplus.common.app.Constants;

/**
 * 主页menu适配器
 * @author norsie
 * @create 13-04-07
 */
public class HomeMenuAdapter extends BaseAdapter
{
    
    private ArrayList<HashMap<String, String>> mData;
    private LayoutInflater mInflater;
    
    public HomeMenuAdapter(Context context,ArrayList<HashMap<String, String>> data) {
        this.mData = data;
        mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    public void reflash(ArrayList<HashMap<String, String>> data) {
        mData=data;
        notifyDataSetChanged();
    }
    @Override
    public int getCount()
    {
        // TODO Auto-generated method stub
        if (mData == null)
            return 0;
        return mData.size();
    }

    @Override
    public Object getItem(int position)
    {
        // TODO Auto-generated method stub
        return mData.get(position);
    }

    @Override
    public long getItemId(int position)
    {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent)
    {
        // TODO Auto-generated method stub
        
        ViewHolder holder = null;
        if (convertView == null)
        {
            // 初始化控件
            convertView = mInflater.inflate(R.layout.activity_home_menu_lvitem, null);
            holder = new ViewHolder();
            holder.name=(TextView)convertView.findViewById(R.id.item_name);
            holder.type=(LinearLayout)convertView.findViewById(R.id.item_colorbar);
            holder.id=(TextView)convertView.findViewById(R.id.item_id);
            convertView.setTag(holder);
        }
        else
        {
            holder = (ViewHolder) convertView.getTag();
        }
        
        holder.name.setText(mData.get(position).get(Constants.SNS_ACCOUNT_NAME).toString());
        holder.id.setText(mData.get(position).get(Constants.SNS_UID).toString());
        
        if((mData.get(position).get(Constants.SNSTYPE).toString()).equals(Constants.SNSTYPE_SINA))
            holder.type.setBackgroundResource(R.color.SinaRed);
        else if(mData.get(position).get(Constants.SNSTYPE).toString().equals(Constants.SNSTYPE_TENCENT))
            holder.type.setBackgroundResource(R.color.TencBlue);
        else if(mData.get(position).get(Constants.SNSTYPE).toString().equals(Constants.SNSTYPE_RENREN))
            holder.type.setBackgroundResource(R.color.RenRBlue);
        else if(mData.get(position).get(Constants.SNSTYPE).toString().equals(Constants.SNSTYPE_WEIXIN))
            holder.type.setBackgroundResource(R.color.WeixinGreen);
        
      //如果已经过期，改变字体颜色以作提醒
        
        return convertView;
    }
    
    static class ViewHolder
    {
        TextView name; // 用户名
        TextView id;//帐号id
        LinearLayout type; // 类别
    }

}
